package com.example.demo;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
public class SimpleConvert {
    // 定义一个ISO 8601格式的DateTimeFormatter
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

    public static Date convertIsoStringToDate(String isoDateStr) {
        // 将输入字符串中的时区部分从+0800调整为+08:00以便于解析
        String modifiedIsoDateStr = isoDateStr.substring(0, isoDateStr.length() - 2)
                + ":"
                + isoDateStr.substring(isoDateStr.length() - 2);

        // 解析字符串到OffsetDateTime
        OffsetDateTime odt = OffsetDateTime.parse(modifiedIsoDateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));

        // 转换为java.util.Date
        return Date.from(odt.toInstant());
    }

    public static void main(String[] args) {
        String dateStr = "2025-02-03T18:11:11.025+0800";
        Date date = convertIsoStringToDate(dateStr);
        System.out.println(new SimpleDateFormat("HHmmssSSSZ").format(date));
    }
}
